var id;
var groupid;
var iconid;
var subid;
var menuid;
var dictBasicType;
var radioVal;
$(function(){
   	 groupid = ly.getUrlParam("groupid");
	 iconid = ly.getUrlParam("iconid");
	 subid = ly.getUrlParam("subid");
	 menuid = ly.getUrlParam("menuid");	

	dictBasicType = ly.getUrlParam("dictBasicType");
	id = ly.getUrlParam("id");
		$(".title_body").html("编辑");
		  $(".form").getForm({
			eventId:id,
			ajaxform:true
	   },function (data) {
		   console.log(data)
		   var html ="";
		   var html2 = '';
		   if(data.picList){
			for (let i = 0; i < data.picList.length; i++) {
				html+= '<div id="eventImg">'
				html+=  '<img  src="'+data.picList[i]+'" alt="">'
				html+= '</div>'	
			}
			$("#eventImg").html(html)
		   }else{
			   $("#eventImgBox").hide()
		   }
		   if(data.audioList){
			for (let i = 0; i < data.audioList.length; i++) {

				// html2 += '<a  target="_blank" href='+ data.audioList[i] + ' download=' + data.audioList[i] + ' >录音下载</a>'
				var audioPath = "'"+data.audioList[i]+"'";
				var fileName = "'"+data.audioFileUploadList[i].fileName+"'";
				html2 += '<a target="_blank" href="javascript:void(0)" onclick="downloadMp3('+audioPath+','+fileName+')" '+' >录音下载</a> ' +
					'<a id="filedown" class="hide" style="visibility: hidden;" target="_black">下载</a>'
		    }
			
	    	$('#audio_play').html(html2);
		}else{
			$('#audio_show').hide()
		}
		


				if(data.eventProgress == 2){
					$("input[name='map']").eq(0).attr("checked",true)
				}else if(data.eventProgress == 3){
					$("input[name='map']").eq(1).attr("checked",true)
				}
			var map = new BMap.Map("allmap");
			var point = new BMap.Point(data.eventLog, data.eventLat);
			map.centerAndZoom(point, 15);
			var marker = new BMap.Marker(point);  // 创建标注
			map.addOverlay(marker);     
			
	    	$("#isUsing").getSelect({
				type:"radio",
				asName:"isUsing",
				list:[
						{value:"1",display:"启用"},
						{value:"2",display:"禁用"}
			    	],
				default:data.isUsing!=null&&data.isUsing==false?'1':'2'
			});
	    });

	
	//------------------------------------地图START----------------------------------------------
          // 将标注添加到地图中
	// var points = [];
	// 	for (let i = 0; i < data.length; i++) {
	// 		var sum = {};
	// 		//points.push( new BMap.Point( o.taskLog , o.taskLat))
	// 		sum.lng = o.taskLog;
	// 		sum.lat = o.taskLat;
	// 		sum.data = 1;
	// 		points.push(sum)
			
	// 	}
	// var bm = new BMap.Map("allmap");

	// bm.centerAndZoom(new BMap.Point(points[0].lng, points[0].lat), 15);
	// bm.setZoom(15);
	// bm.enableScrollWheelZoom(true);
	// translateCallback = function (data) {
	// 	if (data.status === 0) {
	// 		for (var i = 0; i < data.points.length; i++) {

	// 			var label = new BMap.Label((i + 1), {
	// 				offset: new BMap.Size(5, 4)
	// 			});
	// 			label.setStyle({
	// 				background: 'none',
	// 				color: '#fff',
	// 				border: 'none' //只要对label样式进行设置就可达到在标注图标上显示数字的效果
	// 			});
	// 			var marker = new BMap.Marker(data.points[i]);
	// 			marker.setLabel(label); //显示地理名称 a

	// 			bm.addOverlay(marker);
	// 			bm.setCenter(data.points[i]);
	// 		}
	// 	}
	// }
	// setTimeout(function () {
	// 	var convertor = new BMap.Convertor();
	// 	convertor.translate(points, 1, 5, translateCallback)
	// }, 1000);



	//---------------------------------------地图END-------------------------------------------


	//获取到选择的值
	$("input[name=map]").on("click",function(){
	
		radioVal = this.value
	});
	
	//提交
    $("body").on("click","#save-btn-commodityClassification",function(event){
        event.preventDefault();
        var success =  $('.form').validate('submitValidate');
        if(success){
            //验证通过提交表单
            submitFom();
        }
    })
	


	
});

/*
 * 提交表单
 */
function submitFom(){
  
  	var obj = {};
  	var url = site.apiUrl+"/moble/userEvent/updateEventProgress";
  		obj = {
  			'eventProgress':radioVal,
  			'eventId':id
  		};
  	
	request({
		url:url,
		data:obj,
		type:"get",
		ajaxform:true,
		callback:function(f) {
			 console.log(f);
			if(f.code=="rest.success"){
				if(dictBasicType == 1){
					ly.alert('保存成功',function(){	            
			    		ly.goto("EventList.html");
			        });
				}else{
					ly.alert('修改成功',function(){	           
			    		ly.goto("EventList.html");
			        });
				}
			}else{
				ly.toast(f.desc);
			}
		}
	});
  	
}

/**
 * 下载mp3
 * @param audioPath
 */
function downloadMp3(audioPath,fileName) {
	var url = site.apiUrl+"/moble/userEvent/downAudio?audioPath="+audioPath+"&fileName="+fileName;
	$("#filedown").attr("href",url);
	document.getElementById("filedown").click();
	console.log(1111);
}

